package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class delete implements IOperation {
    @Override
    public void work(BookList bookList) {
        System.out.println("删除图书");
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入你要删除的图书");
        String name = scan.nextLine();
        int currentsize = bookList.getUserSize();
        for (int i = 0; i < currentsize; i++) {
            Book book = bookList.getBook(i);
            if (book.getName().equals(name)) {
                for (int j = i + 1; j < currentsize ; j++) {
                    bookList.setBooks(i, bookList.getBook(j));
                }
                bookList.setUserSize(currentsize-1);
                System.out.println("删除成功！");
                return;
            }
        }
        System.out.println("没有找到这本书，删除失败！");
    }
}
